package com.stars.home.activity

import android.os.Bundle
import android.util.Log
import android.view.View
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.home.adapter.BillToAdapter
import com.stars.home.base.MBRActivity
import com.stars.home.databinding.ActivityBillBinding
import com.stars.home.inte.ChoiceData
import com.stars.home.inte.ChoiceListData
import com.stars.home.utils.PopuChoseTime
import com.stars.home.utils.PopuChoseTypeUtils
import com.stars.home.vmodel.BillVModel
import com.trailer.base.net.IResp
import com.trailer.base.net.PageData
import java.text.SimpleDateFormat
import java.util.*
import kotlin.math.log

/**
 *on 2022/9/23
 */
class BillActivity : MBRActivity<BillVModel, BillToAdapter, ActivityBillBinding>() {

//    override fun __before() {
//        super.__before()
//        //获取当前月份
//        var s= SimpleDateFormat("yyyy-MM").format(Date())
//        var  simpleDateFormat = SimpleDateFormat("yyyy-MM")
//        var  date =simpleDateFormat.parse(s)
//        var  ts = date.time
//        vm.time=ts.toString()
//
//    }



    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        var s = SimpleDateFormat("yyyy-MM").format(Date())
        var simpleDateFormat = SimpleDateFormat("yyyy-MM")
        var date = simpleDateFormat.parse(s)
        var ts = date.time
        vm.time = ts.toString()
        binding.tvTime.text = SimpleDateFormat("yyyy-MM").format(Date())
        vm.getCount()
    }

    override fun listeners() {
        super.listeners()

        binding.llAll.onClick {
            PopuChoseTypeUtils.show(context(), binding.llAll, object : ChoiceListData {
                override fun onRestuse(id: String?, name: String?) {

                    vm.type = id
                    binding.tvAll.text = name
                    vm.getCount()
                    onRefresh()

                }


            })
        }

        binding.llTime.onClick {
            //时间

            PopuChoseTime.show(context(), binding.llTime, object : ChoiceListData {
                override fun onRestuse(time: String?, type: String?) {
                    vm.timeType = type
                    //时间
                    binding.tvTime.text = time

                    Log.e("-time-", "type=: " + type)
                    Log.e("-time-", "time=: " + time)


                    if (type == "0") {
                        var simpleDateFormat = SimpleDateFormat("yyyy-MM")

                        var date = simpleDateFormat.parse(time)
                        var ts = date.time
                        vm.time = ts.toString()

                    } else {
                        var simpleDateFormat = SimpleDateFormat("yyyy-MM-dd")

                        var date = simpleDateFormat.parse(time)
                        var ts = date.time
                        vm.time = ts.toString()
                    }
                    vm.getCount()
                    onRefresh()


                }

            })

        }
    }

    override fun vmClass(): Class<BillVModel> {
        return BillVModel::class.java
    }

    override fun binding(): ActivityBillBinding {
        return ActivityBillBinding.inflate(layoutInflater)
    }

    override fun initAdapter(): BillToAdapter {
        return BillToAdapter(vm)
    }

    override fun title(): String? {
        return "明细"
    }

    override fun onRefresh() {
        super.onRefresh()
        vm.getCount()
    }
}
